# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gnu-libiconv
pkgver=1.15
pkgrel=3
pkgdesc="GNU charset conversion library for libc which doesn't implement it"
url="https://www.gnu.org/software/libiconv"
arch="all"
license='LGPL'
depends=""
source="https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$pkgver.tar.gz"
subpackages="$pkgname-doc $pkgname-dev"

builddir="$srcdir"/libiconv-$pkgver
build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--disable-nls \
		--disable-static \
		--enable-extra-encodings
	# since users of this package use this package to work around missing features in musls iconv,
	# enable extra encodings (like the CP437) to be closer to glibcs iconv.

	# work around rpath issue
	sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
	sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
	make
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir/" install
	rm "$pkgdir"/usr/lib/charset.alias

	# move headers so they dont clash with libc headers
	mkdir "$pkgdir"/usr/include/gnu-libiconv
	mv "$pkgdir"/usr/include/*.h "$pkgdir"/usr/include/gnu-libiconv
	mv "$pkgdir"/usr/bin/iconv "$pkgdir"/usr/bin/gnu-iconv

}

sha512sums="1233fe3ca09341b53354fd4bfe342a7589181145a1232c9919583a8c9979636855839049f3406f253a9d9829908816bb71fd6d34dd544ba290d6f04251376b1a  libiconv-1.15.tar.gz"
